import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EmployeeGUI extends JFrame {

	static JTextField firstNameTextField;
	static JTextField lastNameTextField;
	static JTextField ageTextField;
	static JTextField ssnTextField;
	static JTextField employeeIDTextField;
	static JTextField salaryTextField;
	static JTextField supervisorTextField;

	public EmployeeGUI() {
		setLayout(new GridLayout(8, 2, 5, 5));
		setTitle("Employee");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(300,300);
		
		add(new JLabel(" First Name: "));
		firstNameTextField = new JTextField();
		add(firstNameTextField);
		
		add(new JLabel(" Last Name: "));
		lastNameTextField = new JTextField();
		add(lastNameTextField);
		
		add(new JLabel(" Age: "));
		ageTextField = new JTextField();
		add(ageTextField);
		
		add(new JLabel(" SSN: "));
		ssnTextField = new JTextField();
		add(ssnTextField);
		
		add(new JLabel(" Employee ID: "));
		employeeIDTextField = new JTextField();
		add(employeeIDTextField);
		
		add(new JLabel(" Salary: "));
		salaryTextField = new JTextField();
		add(salaryTextField);
		
		add(new JLabel(" Supervisor: "));
		supervisorTextField = new JTextField();
		add(supervisorTextField);
		
		JButton submit = new JButton("Submit");
		add(submit);
		EmployeeSubmitListener listener1 = new EmployeeSubmitListener();
		submit.addActionListener(listener1);
		
		
		JButton cancel = new JButton("Cancel");
		cancel.addActionListener(new EmployeeCancelListener());
		add(cancel);
	}

}

class EmployeeSubmitListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		Employee m;
		int age = Integer.parseInt(EmployeeGUI.ageTextField.getText());
		double salary = Double.parseDouble(EmployeeGUI.salaryTextField.getText());
	    m = new Employee(EmployeeGUI.firstNameTextField.getText(), EmployeeGUI.lastNameTextField.getText(), age, 
	    		EmployeeGUI.ssnTextField.getText(), EmployeeGUI.employeeIDTextField.getText(), salary, EmployeeGUI.supervisorTextField.getText());
	    System.out.println(m.toString());
	    Main.chooserframe.setVisible(true);
		Main.employeeframe.setVisible(false);
		EmployeeGUI.firstNameTextField.setText("");
		EmployeeGUI.lastNameTextField.setText(""); 
		EmployeeGUI.ageTextField.setText(""); 
		EmployeeGUI.ssnTextField.setText("");
		EmployeeGUI.salaryTextField.setText("");
		EmployeeGUI.employeeIDTextField.setText("");
		EmployeeGUI.supervisorTextField.setText("");
	}
}

class EmployeeCancelListener implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		Main.chooserframe.setVisible(true);
		Main.employeeframe.setVisible(false);
		EmployeeGUI.firstNameTextField.setText("");
		EmployeeGUI.lastNameTextField.setText(""); 
		EmployeeGUI.ageTextField.setText(""); 
		EmployeeGUI.ssnTextField.setText("");
		EmployeeGUI.salaryTextField.setText("");
		EmployeeGUI.employeeIDTextField.setText("");
		EmployeeGUI.supervisorTextField.setText("");
	}
}